﻿#Requires AutoHotkey v2.0

Lerp(a, b, t) {
  return a + t * (b - a)
}

easeIn(t) {
  return t * t ; t^2
}

easeOut(t) {
  return 1 - (1 - t) ** 2 ; 1 - (1 - t)^2
}

backIn(t) {
  s := 1.70158 ;  // 控制回弹的大小
  return t * t * ((s + 1) * t - s)
}

backOut(t) {
  s := 1.70158
  return --t * t * ((s + 1) * t + s) + 1
}

easeInOut(t) {
  if (t < 0.5) {
    return 2 * t * t ; // 前半段加速
  } else {
    return -1 + (4 - 2 * t) * t ; // 后半段减速
  }
}

linear(t) {
  return t
}

bounceOut(t) {
  if (t < (1 / 2.75)) {
    return 7.5625 * t * t
  } else if (t < (2 / 2.75)) {
    return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75
  } else if (t < (2.5 / 2.75)) {
    return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375
  } else {
    return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375
  }
}

; 栗子
; g := Gui('-Caption -Resize')
; g.Show('w100 h100 y100')

; curTime := A_TickCount
; duration := 500, dist := 600

; SetTimer fn, 10

; fn(*) {
;   g.GetPos(, , , &h)
;   g.Move(, , , Floor(Lerp(100, dist, bounceOut((A_TickCount - curTime) / duration))))
;   ToolTip h '--' (A_TickCount - curTime) / 1000
;   if h >= dist or A_TickCount - curTime >= duration {
;     SetTimer fn, 0
;     g.Move(, , , dist)
;   }
; }